<!--
 * @Description:  ShiTingDetail - 试听详情
 * @Author: your name
 * @Date: 2024-06-26
 * @LastEditTime: 2024-06-26
 * @LastEditors: Please set LastEditors
-->

<template>
  <div class="shitingInfo">
    <div class="layout">
      <div class="handpick heart_w">
        <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item>课程</el-breadcrumb-item>
          <el-breadcrumb-item>{{ boxTitle }}</el-breadcrumb-item>
        </el-breadcrumb>

        <div v-for="item_t in goodsInfoList" :key="item_t.id">
          <div class="container_content" v-if="item_t.position == nowposition">
            <div class="container_content_imagelist">
              <el-carousel
                trigger="click"
                height="336px"
                indicator-position="outside"
              >
                <el-carousel-item>
                  <el-image :src="item_t.image"></el-image>
                </el-carousel-item>
              </el-carousel>
            </div>

            <div
              class="container_content_message"
              style="
                display: flex;
                flex-direction: column;
                justify-content: space-between;
              "
            >
              <h3>{{ item_t.title_h }}</h3>
              <div class="message_dis" style="flex: 2">
                <h3>课程简介：</h3>
                <p>
                  {{ item_t.describe }}
                </p>
              </div>

              <div class="handle">
                <div @click="CollectionAdd">
                  <i class="iconfont icon-shoucang" v-if="coll_val"></i>
                  <i
                    class="iconfont icon-shoucang2"
                    style="color: #ff8140"
                    v-else
                  >
                  </i>
                  收藏
                </div>
                <div>
                  <el-button
                    type="primary"
                    round
                    class="btns_t"
                    style="
                      background: linear-gradient(-90deg, #46c564, #afe46a);
                    "
                    @click="applyHearing(item_t.id)"
                  >
                    申请试听
                  </el-button>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div class="container heart_w">
      <div class="container_detils">
        <div class="detils_con">
          <!-- tabs栏 -->
          <div class="container_selectTap">
            <div class="selectTap_item">
              <div class="selectTap_tip" :style="{ left: select_val + 'px' }">
                <img
                  src="http://zhishifufei.crmeb.net/pc/images/select.png"
                  alt=""
                />
              </div>
              <div
                :class="{ selectTap: true, selectEd: rankId == index }"
                v-for="(item, index) in tabsList"
                :key="item.tid"
              >
                <span>{{ item.name }}</span>
              </div>
            </div>
          </div>

          <div class="container_content_detils">
            <!-- 1. 详情 -->
            <div class="detils_content" v-if="baseId_img == '详情'">
              <p>
                <!-- <img
                    src="http://cremb-zsff.oss-cn-beijing.aliyuncs.com/cb51d202103301112066634.jpg"
                  /> -->
                {{ goodsInfoList[com]?.content }}
              </p>
            </div>
          </div>
        </div>

        <!-- 推荐课程 -->
        <div class="detils_propaganda">
          <div class="propaganda_recommend">
            <div class="recommend_more">
              <div>相关课程推荐</div>
              <div>更多<i class="el-icon-arrow-right"></i></div>
            </div>
            <div class="propaganda_con">
              <div>
                <a
                  href="javascript:void(0);"
                  @click="handpick_ck"
                  v-for="item_li in 2"
                  :key="item_li.id"
                >
                  <el-image :src="item_li.image"></el-image>
                  <div>
                    <div class="title">CFA课程</div>
                    <div class="browse-money"></div>
                    <div class="label-count">
                      <div>8人已学</div>
                      <div class="money">
                        ￥
                        <span>100.00</span>
                      </div>
                    </div>
                  </div>
                </a>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <transition name="el-fade-in">
      <div class="freeImage" v-show="showFreeImage">
        <div class="image_box">
          <div class="stpop">
            <i
              class="el-icon-close"
              @click="showFreeImage = !showFreeImage"
            ></i>
            <div class="images_t">
              <img :src="freeObj.image" alt="" />
            </div>
            <p>注：{{ freeObj.title }}</p>
          </div>
        </div>
      </div>
    </transition>
  </div>
</template>

<script>
import { addComboCollection } from '@/api/handpick.js'
import { getShitingInfo, getFreeImage } from '@/api/audition'

export default {
  name: 'ShiTingDetail',
  data() {
    return {
      showFreeImage: false,
      freeObj: {},
      rankId: 0,
      boxTitle: '',
      baseId_img: '详情',
      idt: '',
      com: 0,
      nowposition: 1, //当前
      goodsInfoList: [],
      coll_val: true,
      select_val: 0,
      tabsList: [
        {
          name: '详情',
          tid: 113
        }
      ]
    }
  },
  created() {
    this.idt = this.$route.query.id
    // console.log(this.$route.query)
    this.getListInfo()
  },
  mounted() {},
  methods: {
    getListInfo() {
      let _that = this
      let position_num = 0
      getShitingInfo({ id: this.idt }).then(({ data: data }) => {
        this.boxTitle = data.data.box.title
        let subjectArr = []
        data.data.goods.map((ele, index) => {
          position_num++
          if (ele.position) {
            ele.position = ele.position
          } else {
            ele.position = position_num
          }

          if (ele.title_h) {
            ele.title_h = ele.title_h
          } else {
            ele.title_h = data.data.box.title
          }

          if (ele.titleArr) {
            ele.titleArr = ele.titleArr
          } else {
            let arr = {
              id: position_num,
              title_t: ele.title
            }
            subjectArr.push(arr)
            ele.titleArr = subjectArr
          }

          _that.goodsInfoList.push(ele)
          return ele
        })
      })
    },
    async applyHearing(Id) {
      const { data: data } = await getFreeImage({ free_id: Id })
      if (data.code == 1) {
        this.freeObj = data.data
        this.showFreeImage = true
      }
    },
    handpick_ck() {
      // 推荐课程
      this.$router.push({ path: '/handpick_kc', query: { id: 2 } })
      this.refreshT()
    },
    async CollectionAdd() {
      this.coll_val = !this.coll_val
      if (this.coll_val == false) {
        await addComboCollection({ id: 1 })
        layer.msg('收藏成功')
      } else {
        await addComboCollection({ id: 1 })
        layer.msg('取消收藏')
      }
    }
  }
}
</script>

<style scoped lang="scss">
@import '@/assets/styles/handpick.scss';

.course_catalogue {
  .second_level {
    padding: 16px;
    background: #f5f8fa;
    border-radius: 8px;
    margin-bottom: 16px;
    cursor: pointer;

    .LevelItem {
      display: flex;
      align-items: center;
      justify-content: space-between;
      line-height: 35px;
      padding: 0 12px;
    }
  }
}

.shitingInfo {
  .freeImage {
    position: fixed;
    z-index: 9999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);

    .image_box {
      position: absolute;
      width: 300px;
      height: 275px;
      background: #fff;
      left: 50%;
      top: 50%;
      border-radius: 5px;
      transform: translate(-50%, -50%);
      .stpop {
        display: flex;
        height: 80%;
        // align-items: center;
        text-align: center;
        flex-direction: column;
        justify-content: space-between;
        position: relative;
        .el-icon-close {
          font-size: 25px;
          font-weight: normal;
          text-align: right;
          height: 30px;
          line-height: 30px;
          color: rgb(144, 147, 153);
          cursor: pointer;
          width: 40px;
          position: absolute;
          text-align: center;
          right: 5px;
          top: 5px;
        }

        .images_t {
          width: 150px;
          height: 150px;
          margin: 0 auto;
          margin-top: 38px;
          img {
            width: 100%;
            height: 100%;
          }
        }

        p {
          font-family: PingFang SC;
          font-weight: 400;
          font-size: 14px;
          color: #fa7938;
        }
      }
    }
  }
}
</style>
